package com.itheima.service.impl;

import com.itheima.common.DefaultException;
import com.itheima.service.TestService;
import com.itheima.utils.MinIOUtil;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * <h1>ysm</h1>
 *
 * @author <a href="11n_yd2h5e1jx8@dingtalk.com">叶世铭</a>
 * @since 2024/1/3
 */
@Service
public class TestServiceImpl implements TestService {
    @Resource
    private MinIOUtil minIOUtil;

    @Override
    public String upload(MultipartFile file) throws DefaultException {
        String fileUrl;
        try {
            fileUrl = minIOUtil.putObject(file);
        } catch (Exception e) {
            throw new DefaultException("上传异常");
        }
        return fileUrl;
    }

    @Override
    public void downLoad(HttpServletResponse response, String filePath) throws DefaultException {
        try {
            minIOUtil.getObject(response, filePath);
        } catch (Exception e) {
            throw new DefaultException("下载异常");
        }
    }
}
